class TalkeesController < ApplicationController
  before_filter :load_talk
  
  # GET /talkees
  # GET /talkees.xml
  def index
    @talkees = @talk.talkees.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @talkees }
    end
  end

  # GET /talkees/1
  # GET /talkees/1.xml
  def show
    @talkee = @talk.talkees.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @talkee }
    end
  end

  # GET /talkees/new
  # GET /talkees/new.xml
  def new
    @talkee = @talk.talkees.build

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @talkee }
    end
  end

  # GET /talkees/1/edit
  def edit
    @talkee = @talk.talkees.find(params[:id])
  end

  # talk /talkees
  # talk /talkees.xml
  def create
    @talkee = @talk.talkees.build(params[:talkee])
    @talkee.user = User.find(session[:user_id])

    respond_to do |format|
      if @talkee.save
        flash[:notice] = 'Comment was successfully created.'
        format.html { redirect_to(@talk) }
        format.xml  { render :xml => @talkee, :status => :created, :location => @talkee }
      else
        flash[:notice] = 'Comment was not successfully created.'
        format.html { render :action => "new" }
        format.xml  { render :xml => @talkee.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /talkees/1
  # PUT /talkees/1.xml
  def update
    @talkee = @talk.talkees.find(params[:id])

    respond_to do |format|
      if @talkee.update_attributes(params[:talkee])
        flash[:notice] = 'Comment was successfully updated.'
        format.html { redirect_to(@talk, @talkee) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @talkee.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /talkees/1
  # DELETE /talkees/1.xml
  def destroy
    @talkee = Talkee.find(params[:id])
    @talkee.destroy

    respond_to do |format|
      format.html { redirect_to(talkees_url) }
      format.xml  { head :ok }
    end
  end
  
  def load_talk
    @talk = Talk.find(params[:talk_id])
  end
end
